<template>
  <div class="app-container">
    <el-row>
      <el-col :span="24">
        <div class="h_top">
          <div class="bread_title">
            <span>登记退还</span>
          </div>
          <div class="save_button">
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-back" size="mini" @click="goBack">返回</el-button>
            </div>
            <div class="buttonBox">
              <el-button type="primary" icon="el-icon-document-checked" size="mini" @click="save">保存</el-button>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <div>
      <el-row>
        <el-form ref="form" :model="data" :inline="true" :rules="formRules">
          <el-row :gutter="10">
            <el-col :xl="3" :lg="4" :md="4" :sm="5">
              <el-form-item prop="coding">
                <div>编号</div>
                <el-input v-model="data.coding" size="mini" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="4" :sm="5">
              <el-form-item prop="name">
                <div>名称</div>
                <el-input v-model="data.name" size="mini" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="4" :sm="5">
              <el-form-item prop="status">
                <div>状态</div>
                <el-select v-model="data.status" size="mini" disabled>
                  <el-option v-for="(item, index) in handBackStatus" :key="index" :value="index" :label="item" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="4" :sm="5">
              <el-form-item prop="apply_admin_id">
                <div>申请人</div>
                <v-select-s v-model="data.apply_admin_id" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="4" :sm="5">
              <el-form-item prop="workorder_id">
                <div>维修单</div>
                <v-select v-model="data.workorder_id" action="cmList" :query="{'category': 1, 'status': 5, 'add_field': 'coding'}" />
              </el-form-item>
            </el-col>
            <el-col :xl="3" :lg="4" :md="4" :sm="5">
              <el-form-item prop="sort">
                <div>排序</div>
                <el-input v-model="data.sort" size="mini" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-tabs>
          <el-tab-pane label="描述">
            <el-row :gutter="10">
              <el-col :span="24">
                <Tinymce id="content" v-model="data.content" />
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-row>
    </div>
  </div>
</template>

<script>
import API from '@/api/stock/handBack'
import VSelect from '@/components/select'
import VSelectS from '@/components/select-search'
import { handBackStatus } from '@/utils/options'
import Tinymce from '@/components/Tinymce/index'
export default {
  inject: ['addOne', 'goUrl'],
  components: {
    VSelect,
    Tinymce,
    VSelectS
  },
  data() {
    return {
      data: {
        coding: '',
        name: '',
        status: 0,
        sort: 100
      },
      handBackStatus,
      formRules: {
        coding: [
          {
            required: true,
            message: '请输入编号',
            trigger: 'blur'
          }
        ],
        name: [
          {
            required: true,
            message: '请输入退还单名称',
            trigger: 'blur'
          }
        ],
        status: [
          {
            required: true,
            message: '请选择状态',
            trigger: 'change'
          }
        ],
        apply_admin_id: [
          {
            required: true,
            message: '请选择申请人',
            trigger: 'change'
          }
        ],
        workorder_id: [
          {
            required: true,
            message: '请选择工单',
            trigger: 'change'
          }
        ],
        sort: [
          {
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created() {
  },
  methods: {
    save() {
      const thisData = this.data
      const thisForm = this.$refs.form
      this.addOne(API, thisData, thisForm)
    },
    goBack() {
      this.goUrl('/stock/back')
    }
  }
}
</script>
